package com.zeta.edw.venus

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

import org.I0Itec.zkclient.ZkClient
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.FileSystem
import org.backuity.clist.{arg, opt}

class ExtractDataConfig extends Config {

//  var zkUrls: String = arg[String](
//    name = "zk-urls",
//    description = "zookeeper connection, in the form host1:port1,host2:port2,..."
//  )

  var partitionColumn: String = arg[String](name = "partition-column")

  var checkColumn: String = arg[String](
    name = "check-column",
    description = "the column to be examined when determining which rows to extract"
  )

//  var defineStartChekTime: String = arg[String](
//    name = "define-start-chekTime",
//    description = "the define-start-chekTime to be examined "
//  )

//  var defineEndChekTime: String = arg[String](
//    name = "define-end-chekTime",
//    description = "the define-end-chekTime to be examined"
//  )

  var datetimeFormat: String = opt[String](default = "yyyyMMddHHmmss")

  var checkStart: Option[String] = opt[Option[String]]()

  var checkEnd: Option[String] = opt[Option[String]]()

  var rangeColumn: Option[String] = opt[Option[String]](
    description = "the range partition column in oracle"
  )

  var overwrite: Boolean = opt[Boolean](default = false)

  lazy val defaultCheckStart: String = LocalDateTime.now()
    .withHour(8).withMinute(0).withSecond(0).withNano(0)
    .format(DateTimeFormatter.ofPattern(datetimeFormat))

  lazy val defaultCheckEnd: String = LocalDateTime.now()
    .withSecond(0).withNano(0).minusMinutes(1)
    .format(DateTimeFormatter.ofPattern(datetimeFormat))

  //2017.5.25
    lazy val defaultCheckStart23: String = LocalDateTime.now()
      .withYear(2017)
      .withMonth(5).withDayOfMonth(25)
      .withHour(0)
      .withMinute(0)
      .withSecond(0)
      .format(DateTimeFormatter.ofPattern(datetimeFormat))
    lazy val defaultCheckEnd23: String = LocalDateTime.now()
      .withYear(2017)
      .withMonth(5).withDayOfMonth(25)
      .withHour(23)
      .withMinute(59)
      .withSecond(59)
      .format(DateTimeFormatter.ofPattern(datetimeFormat))

//  lazy val defaultCheckStart23: String = LocalDateTime.now()
//    .withHour(0).withMinute(0).withSecond(0).withNano(0)
//    .minusDays(1)
//    .format(DateTimeFormatter.ofPattern(datetimeFormat))
//
//  lazy val defaultCheckEnd23: String = LocalDateTime.now()
//    .withHour(0).withMinute(0).withSecond(0).withNano(0)
//    .minusDays(1).withHour(23).withMinute(59).withSecond(59)
//    .format(DateTimeFormatter.ofPattern(datetimeFormat))

 // lazy val zkClient = new ZkClient(zkUrls, 100000, 30000, ZKStringSerializer)

 // lazy val zkTablePath = s"/edw/bdp/tables/$hiveTable"

  lazy val datetimeFormatMapping = Map(
    "yyyyMMddHHmmss" -> "yyyymmddhh24miss",
    "yyyy-MM-dd HH:mm:ss" -> "yyyy-mm-dd hh24:mi:ss"
  )

  lazy val fileSystem: FileSystem = {
    val conf = new Configuration()
    conf.set("fs.defaultFS", hdfsUrl)
    FileSystem.get(conf)
  }
}
